// Date: 2021-09-17
import { useQuasar } from '@teld/q-components';
import {FilterExpression} from '../../covert'
import TmButton from 't/basic/button';
import TmCheckbox from 't/basic/checkbox';
import TmCheckboxGroup from 't/basic/checkbox-group';
import TmIcon from 't/basic/icon';
import TmList from 't/basic/list';
import TmPopup from 't/basic/dialog';
import TmSelect from 't/basic/select';
import TTextarea from 't/basic/textarea';
import TmSteps from 't/basic/stepper';

import { defineComponent, ref, toRefs, watch } from 'vue';
export default defineComponent({
  name: 'SubWarning',
  components: {
    TmIcon,
    TmPopup,
    TmSteps,
    TmSelect,
    TmList,
    TmCheckboxGroup,
    TmCheckbox,
    TmButton,
    TTextarea,
  },
  props: {
    modifyPlan: Object,
    currectPlan: String,
    filter: Object,
    showSubWarning: Boolean,
    pageID: String,
    dataQuery: String,
    filterServer: Array,
    pageName: String,
    pageCode: String,
  },
  setup(props, { emit }) {
    const $q = useQuasar();
    const showNotify = $q.notify;
    const {
      showSubWarning,
      modifyPlan,
      pageID,
      dataQuery,
      filterServer,
      pageName,
      pageCode,
    } = toRefs(props);
    const active = ref(1);
    const isReadOnly = ref(false);
    const WarnSubObj = ref({
      Name: '', // 订阅名称
      Description: '', // 订阅名称
      SourceType: 0, // 默认
      SourceID: '', // 查询方案id
      SourceName: '', //查询方案名称
      IsEnable: true, // 默认true
      JSContent: '', // DQ数据源
      JSContentParams: '', // DQ的过滤条件
      IsBasic: false, // 默认false
      ReturnType: 11, // 默认11
      BusinessType: '', // 界面的Code
      BusinessName: '', // 界面的名称
      LinkUrl: '', // 当前界面的地址document.URL
      TriggerType: 1, // 订阅条件
      ComplexTriggerCondition: '',
      ComplexTriggerConditionView: {
        //订阅条件 == 3自定义 时
        CompareOperation: 0, // 条件
        CompareValue: 1, // 预期值
      },
      NoticeSet: {
        SortOrder: 0, // 默认0
        NoticeType: '', // 通知范围
        SubscriptionNoticeDefinitionID: '', // 通知方式ID
        NoticeContentType: 0,
        NoticeContent: '', // 通知内容
        TokenInfo: '', // Token
        SecretInfo: '', // Secrect
        IsNeedAtPerson: false, // 是否通知并@人员
        PersonField: '', // 字段Code
      },
      NoticeSets: [],
      //订阅频率
      ExecuteFrequency: {
        SysFrequencies: [],
      },
      WarnSubRateDay: '', //Terms.warnSub.WarnSubRateDay,
      WarnSubRateHour: '9:00',
      QueryPlanID: '',
    });
    watch(
      () => modifyPlan.value,
      () => {
        isReadOnly.value = modifyPlan.value.WarningID;
        if (!isReadOnly.value) {
          WarnSubObj.value.plan = modifyPlan.value;
          WarnSubObj.value.Name = modifyPlan.value.Name +$q.lang.queryPlan.subWarning.warnName;
          WarnSubObj.value.SourceID = modifyPlan.value.ID;
          WarnSubObj.value.SourceName = modifyPlan.value.Name;
        }
      },
      {
        immediate: true,
      },
    );
    const GetSysExecuteFrequencies = () => {
      return TFF.common.ajax.getDataAsync({
        url: `${Funcs.FasRequestTagAdd(
          TFF.common.ajax.getServiceUrl('FASR-GetSysExecuteFrequencies'),
        )}`,
        type: 'post',
        data: null,
      });
    };
    // 创建计划任务订阅
    const CreateScheduleJobSubscription = subscription => {
      return TFF.common.ajax.getDataAsync({
        url: `${Funcs.FasRequestTagAdd(
          TFF.common.ajax.getServiceUrl('FASR-CreateScheduleJobSubscription'),
        )}`,
        type: 'post',
        data: {
          subscription: JSON.stringify(subscription),
        },
      });
    };
    const GetNoticeScopeSets = () => {
      if (!window.TFF) {
        return Promise.resolve({
          state: '1',
          message: $q.lang.queryPlan.subWarning.saveSuccess,
          data: false,
        });
      }
      if (!window.GetNoticeScopeSetsProxy) {
        window.GetNoticeScopeSetsProxy = TFF.common.ajax.getDataAsync({
          url: `${Funcs.FasRequestTagAdd(
            TFF.common.ajax.getServiceUrl('FASR-GetNoticeScopeSets'),
          )}`,
          type: 'post',
          data: null,
        });
      }
      if (window.GetNoticeScopeSetsProxy instanceof Promise) {
        return window.GetNoticeScopeSetsProxy;
      } else {
        return Promise.resolve(window.GetNoticeScopeSetsProxy);
      }
    };
    const CancleScheduleJobSubscription = subscriptionID => {
      return TFF.common.ajax.getDataAsync({
        url: `${Funcs.FasRequestTagAdd(
          TFF.common.ajax.getServiceUrl('FASR-CancleScheduleJobSubscription'),
        )}`,
        type: 'post',
        data: {
          subscriptionID: subscriptionID,
        },
      });
    };

    const formatToObject = data => {
      if (!data.map) return [];
      return data.map((element, index) => {
        return {
          label: element,
          value: element,
        };
      });
    };
    const formatObjectToArray = data => {
      if (!(data instanceof Object)) return [];
      let res = [];
      for (let i in data) {
        res.push({
          label: data[i],
          value: i,
        });
      }
      return res;
    };
    const settingConfig = ref({
      SubscriptionNoticeContentType: [],
      SubscriptionNoticeSets: [],
      DayValue: [],
      HourValue: [],
      NoticesDefines: [],
    });
    let NoticesDefines = {};
    const GetScheduleJobSubscriptionById = subscriptionID => {
      return TFF.common.ajax.getDataAsync({
        url: `${Funcs.FasRequestTagAdd(
          TFF.common.ajax.getServiceUrl('FASR-GetScheduleJobSubscriptionById'),
        )}`,
        type: 'post',
        data: {
          subscriptionID: subscriptionID,
        },
      });
    };

    const renderBasicInfo = isNotCreate => {
      return (
        <div
          class={
            isNotCreate
              ? 'subwarning_basicInfo_m subwarning_basicInfo_m_height_Auto'
              : 'subwarning_basicInfo_m'
          }
        >
          <p>
            <t-input
              class={'tr-input-form'}
              label={ $q.lang.queryPlan.subWarning.subWarningName}
              borderType='borderless'
              type='text'
              {...(isReadOnly.value ? { readonly: true } : {})}
              v-model={WarnSubObj.value.Name}
            />
          </p>
          <p>
            <t-input
              label={ $q.lang.queryPlan.subWarning.functionName}
              borderType='borderless'
              type='text'
              class={'tr-input-form'}
              readonly
              v-model={pageName.value}
            />
          </p>
          <p>
            {/* <span>方案名称</span> */}
            <t-input
              label={ $q.lang.queryPlan.dialog.planName}
              class={'tr-input-form'}
              borderType='borderless'
              type='text'
              readonly
              v-model={WarnSubObj.value.SourceName}
            />
          </p>
        </div>
      );
    };
    const WarnSubConditionOptions = [
      { value: 1, label: $q.lang.queryPlan.subWarning.WarnSubConditionOptions[0]},
      { value: 2, label: $q.lang.queryPlan.subWarning.WarnSubConditionOptions[1] },
      { value: 3, label: $q.lang.queryPlan.subWarning.WarnSubConditionOptions[2] },
    ];
    const WarnSubDataConditionOptions = [
      { value: 0, label: $q.lang.dataGrid.filterOperation.greaterThan  },
      { value: 1, label: $q.lang.dataGrid.filterOperation.lessThan  },
      { value: 2, label: $q.lang.dataGrid.filterOperation.equal  },
      { value: 3, label: $q.lang.dataGrid.filterOperation.notEqual },
      { value: 4, label: $q.lang.dataGrid.filterOperation.lessThanOrEqual},
      { value: 5, label: $q.lang.dataGrid.filterOperation.greaterThanOrEqual},
    ];

    const renderSubInfo = isNotCreate => {
      //FASR-GetNoticeScopeSets
      /**
       * 订阅条件
       *  WarnSubConditionOptions: [
        { value: 1, label: '数据条数大于0时' },
        { value: 2, label: '数据条数小于0时' },
        { value: 3, label: '自定义' },
      ],
      WarnSubDataConditionOptions: [
        { value: 0, label: Terms.warnSub.moreThan },
        { value: 1, label: Terms.warnSub.lessThan },
        { value: 2, label: Terms.warnSub.equal },
        { value: 3, label: Terms.warnSub.notEqual },
        { value: 4, label: Terms.warnSub.notMoreThan },
        { value: 5, label: Terms.warnSub.notLessThan },
      ],
       */
      return (
        <div
          class={
            isNotCreate
              ? 'subwarning_basicInfo_m subwarning_basicInfo_m_height_Auto'
              : 'subwarning_basicInfo_m'
          }
        >
          <p>
            {/* <span>订阅条件</span> */}
            <tm-select
              label={$q.lang.queryPlan.subWarning.subCondition}
              v-model:modelValue={WarnSubObj.value.TriggerType}
              hideLabel={true}
              label={$q.lang.queryPlan.subWarning.choise}
              title={$q.lang.queryPlan.subWarning.choise}
              HelpPlacement='bottom'
              placeholder={$q.lang.queryPlan.subWarning.choise}
              staticItems={WarnSubConditionOptions}
              textAlign='left'
              class={'tr-select-enterform subCondition tr-input-editform'}
              itemsDataSourceType='static'
              {...(isReadOnly.value ? { readonly: true } : {})}
            />
          </p>
          {(() => {
            if (WarnSubObj.value.TriggerType == 3) {
              return (
                <p>
                  {/* <span>数据条数</span> */}
                  <div class='subConditionDataNumber'>
                    <tm-select
                      label={$q.lang.queryPlan.subWarning.dataNum}
                      v-model={
                        WarnSubObj.value.ComplexTriggerConditionView
                          .CompareOperation
                      }
                      hideLabel={true}
                      Label={$q.lang.queryPlan.subWarning.choise}
                      title={$q.lang.queryPlan.subWarning.choise}
                      HelpPlacement='bottom'
                      placeholder={$q.lang.queryPlan.subWarning.choise}
                      staticItems={WarnSubDataConditionOptions}
                      textAlign='left'
                      class={'tr-select-enterform subCondition tr-input-editform'}
                      itemsDataSourceType='static'
                      {...(isReadOnly.value ? { readonly: true } : {})}
                    />
                    <t-input
                      class={'tr-input-form'}
                      {...(isReadOnly.value ? { readonly: true } : {})}
                      borderType='borderless'
                      type='text'

                      v-model={
                        WarnSubObj.value.ComplexTriggerConditionView
                          .CompareValue
                      }
                    />
                    {/* <t-input
                      type='text'
                      style='margin-top:0'
                      {...(isReadOnly.value ? { readonly: true } : {})}
                      v-model={
                        WarnSubObj.value.ComplexTriggerConditionView
                          .CompareValue
                      }
                    /> */}
                  </div>
                </p>
              );
            }
          })()}
          {(() => {
            if (!isNotCreate)
              return (
                <p>
                  {/* <span>订阅频率</span> */}
                  <div class='subConditionDataNumber'>
                    <tm-select
                      label={$q.lang.queryPlan.subWarning.subRate}
                      v-model={WarnSubObj.value.WarnSubRateDay}
                      Label={$q.lang.queryPlan.subWarning.choise}
                      title={$q.lang.queryPlan.subWarning.choise}
                      HelpPlacement='bottom'
                      placeholder={$q.lang.queryPlan.subWarning.choise}
                      staticItems={settingConfig.value.DayValue}
                      itemsDataSourceType='static'
                      textAlign='left'
                      class={'tr-select-enterform subCondition tr-input-editform'}
                      {...(isReadOnly.value ? { readonly: true } : {})}
                    />
                    <tm-select
                      v-model={WarnSubObj.value.WarnSubRateHour}
                      hideLabel={true}
                      Label={$q.lang.queryPlan.subWarning.choise}
                      title={$q.lang.queryPlan.subWarning.choise}
                      HelpPlacement='bottom'
                      itemsDataSourceType='static'
                      placeholder={$q.lang.queryPlan.subWarning.choise}
                      staticItems={settingConfig.value.HourValue}
                      textAlign='left'
                      class={'tr-select-enterform subCondition padding_top_18 tr-input-editform'}
                      {...(isReadOnly.value ? { readonly: true } : {})}
                    />

                    <i
                      class='icon-icon-fasplus'
                      style='margin-top:21px;padding-top:16px'
                      onClick={async () => {
                        if (isReadOnly.value) return;
                        if (
                          WarnSubObj.value.ExecuteFrequency.SysFrequencies.some(
                            item =>
                              WarnSubObj.value.WarnSubRateDay ==
                                item.DayValue &&
                              WarnSubObj.value.WarnSubRateHour ==
                                item.HourValue,
                          )
                        ) {
                          return;
                        }
                        GetSysExecuteFrequencies().then(
                          WarnSubSysFrequencies => {
                            let sysFrequencyObj =
                              WarnSubSysFrequencies.data.find(
                                frequency =>
                                  frequency.DayValue ==
                                    WarnSubObj.value.WarnSubRateDay &&
                                  frequency.HourValue ==
                                    WarnSubObj.value.WarnSubRateHour,
                              );
                            if (!sysFrequencyObj)
                                Funcs.Notify($q.lang.selectHelper.warning, $q.lang.queryPlan.subWarning.subRateIsTemp, 'warning')
                            //@ts-ignore
                            WarnSubObj.value.ExecuteFrequency.SysFrequencies.push(
                              {
                                ID: sysFrequencyObj.ID,
                                CronExpression: sysFrequencyObj.CronExpression,
                                FrequencyContent:
                                  sysFrequencyObj.FrequencyContent,
                                DayValue: WarnSubObj.value.WarnSubRateDay,
                                HourValue: WarnSubObj.value.WarnSubRateHour,
                              },
                            );
                          },
                        );
                      }}
                    ></i>
                  </div>
                </p>
              );
          })()}

          <div class={isReadOnly.value ? 'subList readonly' : 'subList'}>
            <tm-list finished={true}>
              <div class='cell'>
                <div class='cell_value'>
                <p>
                  <span style={'text-align:center'}>{$q.lang.queryPlan.subWarning.order}</span>
                  <span>{$q.lang.queryPlan.subWarning.day}</span>
                  <span>{$q.lang.queryPlan.subWarning.hour}</span>
                  {(() => {
                    if (!isNotCreate)
                      return <span style={'text-align:center'}>{$q.lang.queryPlan.subWarning.operate}</span>;
                  })()}
                </p>
                </div>

              </div>
              <div class='cell'>
                <div class='cell_value cell_list'>
                {(() => {
                  let Template = [];
                  if (
                    WarnSubObj.value.ExecuteFrequency.SysFrequencies &&
                    WarnSubObj.value.ExecuteFrequency.SysFrequencies.length > 0
                  ) {
                    WarnSubObj.value.ExecuteFrequency.SysFrequencies.forEach(
                      (ele, index) => {
                        Template.push(
                          <p>
                            <span style={'text-align:center'}>{index + 1}</span>
                            <span>
                              {
                                settingConfig.value.DayValue.find(
                                  item => item.value == ele.DayValue,
                                ).label
                              }
                            </span>

                            <span>
                              {
                                settingConfig.value.HourValue.find(
                                  item => item.value == ele.HourValue,
                                ).label
                              }
                            </span>

                            {(() => {
                              if (!isNotCreate)
                                return (
                                  <span style={'text-align:center'}>
                                    <i
                                      class={
                                        'fas dx-icon icon-t-delete-outlined'
                                      }
                                      onClick={() => {
                                        WarnSubObj.value.ExecuteFrequency.SysFrequencies =
                                          WarnSubObj.value.ExecuteFrequency.SysFrequencies.filter(
                                            frequency =>
                                              !(
                                                frequency.DayValue ==
                                                  ele.DayValue &&
                                                frequency.HourValue ==
                                                  ele.HourValue
                                              ),
                                          );
                                      }}
                                    ></i>
                                  </span>
                                );
                            })()}
                          </p>,
                        );
                      },
                    );
                  }
                  return Template;
                })()}
             </div>
             </div>
            </tm-list>
          </div>
        </div>
      );
    };
    const WarnSubObj_NoticeContent = ref('');
    const NoticeContent = () => {
      if (!NoticesDefines.find) return;
      //WarnSubObj.value.NoticeSet.SubscriptionNoticeDefinitionID === >settingConfig.value.NoticesDefines
      //WarnSubObj.value.NoticeSet.NoticeContentType === >settingConfig.value.SubscriptionNoticeContentType
      let NoticesDefines_Target = NoticesDefines.find(
        item =>
          item.ID == WarnSubObj.value.NoticeSet.SubscriptionNoticeDefinitionID,
      );
      WarnSubObj.value.NoticeSet.NoticeContentType == 1
        ? (WarnSubObj.value.NoticeSet.NoticeContent =
            NoticesDefines_Target.MarkdownTemplate)
        : (WarnSubObj.value.NoticeSet.NoticeContent =
            NoticesDefines_Target.SimpleMarkdownTemplate);
      return (WarnSubObj_NoticeContent.value =
        WarnSubObj.value.NoticeSet.NoticeContent);
    };
    watch(
      () => WarnSubObj.value.NoticeSet.SubscriptionNoticeDefinitionID,
      () => {
        NoticeContent();
      },
      {
        deep: true,
        immediate: true,
      },
    );
    watch(
      () => WarnSubObj.value.NoticeSet.NoticeContentType,
      () => {
        NoticeContent();
      },
      {
        deep: true,
        immediate: true,
      },
    );
    watch(
      () => showSubWarning.value,
      () => {
        if (showSubWarning.value) {
          GetNoticeScopeSets().then(res => {
            window.GetNoticeScopeSetsProxy = res;
            res = res.data;
            if (!res) return;
            NoticesDefines = res.NoticesDefines;
            settingConfig.value.SubscriptionNoticeContentType =
              formatObjectToArray(res.SubscriptionNoticeContentType);
            WarnSubObj.value.NoticeSet.NoticeContentType
              ? ''
              : (() => {
                  WarnSubObj.value.NoticeSet.NoticeContentType =
                    settingConfig.value.SubscriptionNoticeContentType[0].value;
                  WarnSubObj.value.NoticeSet.NoticeContent =
                    res.NoticesDefines[0].MarkdownTemplate;
                })();

            settingConfig.value.SubscriptionNoticeSets = formatObjectToArray(
              res.SubscriptionNoticeSets,
            );
            WarnSubObj.value.NoticeSet.NoticeType != ''
              ? ''
              : (WarnSubObj.value.NoticeSet.NoticeType =
                  settingConfig.value.SubscriptionNoticeSets[0].value);
            settingConfig.value.DayValue = formatToObject(
              res.SysSubscriptionFrequencies.DayValue,
            );
            settingConfig.value.HourValue = formatToObject(
              res.SysSubscriptionFrequencies.HourValue,
            );
            settingConfig.value.NoticesDefines = res.NoticesDefines.map(
              item => {
                return {
                  NoticeScope: item.NoticeScope,
                  label: item.Name,
                  value: item.ID,
                };
              },
            );

            WarnSubObj.value.NoticeSet.SubscriptionNoticeDefinitionID
              ? ''
              : (WarnSubObj.value.NoticeSet.SubscriptionNoticeDefinitionID =
                  settingConfig.value.NoticesDefines.filter(
                    kk =>
                      kk.NoticeScope == WarnSubObj.value.NoticeSet.NoticeType,
                  )[0].value);
            WarnSubObj.value.WarnSubRateDay =
              settingConfig.value.DayValue[0].value;
            WarnSubObj.value.WarnSubRateHour =
              settingConfig.value.HourValue[0].value;
            NoticeContent();
            if (modifyPlan.value.WarningID) {
              GetScheduleJobSubscriptionById(modifyPlan.value.WarningID).then(
                res => {
                  if (res.data) {
                    res.data.NoticeSet = res.data.NoticeSets[0];
                    if (!res.data.ComplexTriggerConditionView) {
                      res.data.ComplexTriggerConditionView =
                        WarnSubObj.value.ComplexTriggerConditionView;
                    }
                    res.data.NoticeSet.NoticeType = res.data.NoticeSet
                      .SubscriptionNoticeDefinition
                      ? res.data.NoticeSet.SubscriptionNoticeDefinition
                          .NoticeScope + ''
                      : '0';
                    res.data.ComplexTriggerCondition = JSON.parse(
                      res.data.ComplexTriggerCondition,
                    );
                    WarnSubObj.value = res.data;
                    WarnSubObj.value.plan = modifyPlan.value;
                  } else {
                    if (!modifyPlan.value.IsAuth) {
                      delete modifyPlan.value.WarningID;
                      emit('update:showSubWarning', false);
                      return Funcs.Notify($q.lang.selectHelper.warning,$q.lang.queryPlan.subWarning.getSubWarningFail, 'warning')
                    }
                    if (modifyPlan.value.IsAuth) {
                      //  emit('update:showSubWarning', false);
                      delete modifyPlan.value.WarningID;
                      WarnSubObj.value.plan = modifyPlan.value;
                      WarnSubObj.value.Name =
                        modifyPlan.value.Name +  $q.lang.queryPlan.subWarning.warnName;
                      WarnSubObj.value.SourceID = modifyPlan.value.ID;
                      WarnSubObj.value.SourceName = modifyPlan.value.Name;
                      isReadOnly.value = false;
                      return Funcs.Notify($q.lang.selectHelper.warning,$q.lang.queryPlan.subWarning.getSubWarningFailToRety, 'warning')
                    }
                  }
                },
              );
            }
          });
        }
      },
      { immediate: true },
    );
    const renderNotifyInfo = isNotCreate => {
      return (
        <div
          class={
            isNotCreate
              ? 'subwarning_basicInfo_m subwarning_basicInfo_m_height_Auto'
              : 'subwarning_basicInfo_m'
          }
        >
          <p>
            {/* <span>通知范围</span> */}
            <div class='subConditionDataNumber'>
              <tm-select
                label={$q.lang.queryPlan.subWarning.notice}
                class={'tr-select-enterform subCondition tr-input-editform'}
                v-model={WarnSubObj.value.NoticeSet.NoticeType}
                hideLabel={true}
                Label={$q.lang.queryPlan.subWarning.choise}
                title={$q.lang.queryPlan.subWarning.choise}
                HelpPlacement='bottom'
                placeholder={$q.lang.queryPlan.subWarning.choise}
                staticItems={settingConfig.value.SubscriptionNoticeSets}
                itemsDataSourceType='static'
                textAlign='left'
                onConfirm={() => {
                  WarnSubObj.value.NoticeSet.SubscriptionNoticeDefinitionID =
                    settingConfig.value.NoticesDefines.filter(
                      jj =>
                        jj.NoticeScope == WarnSubObj.value.NoticeSet.NoticeType,
                    )[0].value;
                }}
                {...(isReadOnly.value ? { readonly: true } : {})}
              />
              {(() => {
                if (WarnSubObj.value.NoticeSet.NoticeType == 0) {
                  return (
                    <tm-select
                      v-model={
                        WarnSubObj.value.NoticeSet
                          .SubscriptionNoticeDefinitionID
                      }
                      onConfirm={NoticeContent}
                      itemsDataSourceType='static'
                      hideLabel={true}
                      Label={$q.lang.queryPlan.subWarning.choise}
                      title={$q.lang.queryPlan.subWarning.choise}
                      HelpPlacement='bottom'
                      placeholder={$q.lang.queryPlan.subWarning.choise}
                      staticItems={(() => {
                        return settingConfig.value.NoticesDefines.filter(
                          jj =>
                            jj.NoticeScope ==
                            WarnSubObj.value.NoticeSet.NoticeType,
                        );
                      })()}
                      textAlign='left'
                      class={'tr-select-enterform subCondition tr-input-editform'}
                      {...(isReadOnly.value ? { readonly: true } : {})}
                    />
                  );
                }
              })()}
            </div>
          </p>
          {(() => {
            if (!isReadOnly.value) {
              return (
                <p>
                  <div class='subConditionDataNumber' style='width:100%'>
                    <tm-select
                      label={$q.lang.queryPlan.subWarning.noticeTemplate}
                      v-model={WarnSubObj.value.NoticeSet.NoticeContentType}
                      onConfirm={NoticeContent}
                      hideLabel={true}
                      Label={$q.lang.queryPlan.subWarning.choise}
                      title={$q.lang.queryPlan.subWarning.choise}
                      HelpPlacement='bottom'
                      placeholder={$q.lang.queryPlan.subWarning.choise}
                      staticItems={
                        settingConfig.value.SubscriptionNoticeContentType
                      }
                      itemsDataSourceType='static'
                      textAlign='left'
                      class={'tr-select-enterform subCondition tr-input-editform'}
                      style='with:100%'
                      {...(isReadOnly.value ? { readonly: true } : {})}
                    />
                  </div>
                </p>
              );
            }
          })()}

          <p>
            <span></span>
            <div class='subConditionDataNumber' style='width:100%'>
              <t-textarea
                readonly
                borderless={true}
                label={$q.lang.queryPlan.subWarning.noticeContent}
                v-model={WarnSubObj_NoticeContent.value}
                style='width:100%;margin-top:21px'
                class='tr-textarea-form'
              ></t-textarea>
            </div>
          </p>
          {(() => {
            if (WarnSubObj.value.NoticeSet.NoticeType != 0) {
              return (
                <div>
                  <p>
                    <div class='subConditionDataNumber' style='width:100%'>
                      <t-input
                        class={'tr-input-form'}
                        label='Token'
                        borderType='borderless'
                        placeholder={$q.lang.queryPlan.subWarning.tokenPlaceholder}
                        type='text'
                        {...(isReadOnly.value ? { readonly: true } : {})}
                        v-model={WarnSubObj.value.NoticeSet.TokenInfo}
                      />
                    </div>
                  </p>
                  <p>
                    <div class='subConditionDataNumber' style='width:100%'>
                      <t-input
                        class={'tr-input-form'}
                        label='Secret'
                        borderType='borderless'
                        type='text'
                        {...(isReadOnly.value ? { readonly: true } : {})}
                        v-model={WarnSubObj.value.NoticeSet.SecretInfo}
                        placeholder={$q.lang.queryPlan.subWarning.secretPlaceholder}
                      />
                    </div>
                  </p>
                  <p>
                    <span>
                      <tm-checkbox
                        shape='square'
                        size='xs'
                        v-model={WarnSubObj.value.NoticeSet.IsNeedAtPerson}
                        {...(isReadOnly.value ? { disabled: true } : {})}
                      >
                       {$q.lang.queryPlan.subWarning.notifyPerson}
                      </tm-checkbox>
                    </span>
                    <div class='subConditionDataNumber' style='width:100%'>
                      <tm-select
                        v-model={WarnSubObj.value.NoticeSet.PersonField}
                        onConfirm={NoticeContent}
                        hideLabel={true}
                        Label={$q.lang.queryPlan.subWarning.choise}
                        title={$q.lang.queryPlan.subWarning.choise}
                        HelpPlacement='bottom'
                        placeholder={$q.lang.queryPlan.subWarning.choise}
                        staticItems={(() => {
                          return filterServer.value?.map(item => {
                            return {
                              label: item.fieldName,
                              value: item.fieldAlias,
                            };
                          });
                        })()}
                        itemsDataSourceType='static'
                        textAlign='left'
                        style='margin-top:0px !important'
                        class={'tr-select-enterform subCondition tr-input-editform'}
                        {...(isReadOnly.value ? { readonly: true } : {})}
                      />
                    </div>
                  </p>
                </div>
              );
            }
          })()}
        </div>
      );
    };

    const renderSubWarningContent = () => {
      if (active.value == 1) {
        return renderBasicInfo(false);
      } else if (active.value == 2) {
        return renderSubInfo(false);
      } else if (active.value == 3) {
        return renderNotifyInfo(false);
      }
    };
    const refTPopupProxy = ref(null);
    watch(
      () => showSubWarning.value,
      () => {
        if (showSubWarning.value) {
          refTPopupProxy.value.show();
        } else {
          refTPopupProxy.value.hide();
        }
      },
    );
    const render = () => {
      return (
        <tm-popup
          style='height:80vh;width:100vw;bottom:0;background:rgba(0,0,0,0)'
          lock-scroll={true}
          ref={refTPopupProxy}
          class='queryplanContent_m'
          position='bottom'
          v-model:show={showSubWarning.value}
          // 如果设置为false 组件限制无法全屏
          maximized={true}
          onShow={() => {}}
          onHide={() => {
            emit('update:showSubWarning', false);
          }}
        >
          <div
            style='background:#fff;height:80vh !important'
            class={'queryplanContent_m'}
          >
            <header>
              <i
                class={`${TComponents?.IconList?.common??'fas dx-icon'} ${TComponents?.IconList?.arrowLeft??'icon-t-arrow-left'}`}
                onClick={() => {
                  emit('update:showSubWarning', false);
                }}
              ></i>
              {/* <tm-icon
                name='chevron_left'
                onClick={() => {
                  emit('update:showSubWarning', false);
                }}
                style='position:absolute;left:20px'
              /> */}
              <span>
                {modifyPlan.value.WarningID
                  ? modifyPlan.value.IsAuth
                    ? $q.lang.queryPlan.subWarning.cancelSubWarning
                    : $q.lang.queryPlan.subWarning.viewSubWarning
                  : $q.lang.queryPlan.subWarning.subWarning}
              </span>
            </header>
            {(() => {
              if (!modifyPlan.value.WarningID) {
                return (
                  <div>
                    <div>
                      <tm-steps
                        alternativeLabels={true}
                        v-model={active.value}
                        style='border:0'
                        class='subwarning-q-stepper'
                        isShowNav={false}
                        staticItems={[
                          {
                            name: 1,
                            title: $q.lang.queryPlan.subWarning.stepInfo[0],
                            done: active.value > 1,
                          },
                          {
                            name: 2,
                            title: $q.lang.queryPlan.subWarning.stepInfo[1],

                            done: active.value > 2,
                          },
                          {
                            name: 3,
                            title: $q.lang.queryPlan.subWarning.stepInfo[2],

                            done: active.value > 3,
                          },
                        ]}
                      ></tm-steps>
                      <div>{renderSubWarningContent()}</div>
                    </div>
                    <div class='subwarning_foot '>
                      {(() => {
                        if (active.value != 1) {
                          return (
                            <tm-button
                              class='submit'
                              type='primary'
                              style='border:1px solid #DCDCDC;width:50%'
                              onClick={() => {
                                if (active.value > 0) {
                                  active.value--;
                                }
                              }}
                            >
                              {$q.lang.queryPlan.subWarning.prevStep}
                            </tm-button>
                          );
                        }
                      })()}

                      {(() => {
                        if (active.value < 3) {
                          return (
                            <tm-button
                              class='submit'
                              type='primary'
                              color='primary'
                              onClick={() => {
                                if (active.value == 1) {
                                  if (!WarnSubObj.value.Name) {
                                    Funcs.Notify(
                                      $q.lang.selectHelper.warning,
                                      $q.lang.queryPlan.subWarning
                                        .subWarningNameisNotEmpt,
                                      'warning',
                                    );
                                    return;
                                  }
                                } else if (active.value == 2) {
                                  if (WarnSubObj.value.TriggerType == 3) {
                                    if (
                                      !WarnSubObj.value
                                        .ComplexTriggerConditionView
                                        .CompareValue ||
                                      !/(^[1-9]\d*$)/.test(
                                        WarnSubObj.value
                                          .ComplexTriggerConditionView
                                          .CompareValue,
                                      )
                                    ) {
                                      return Funcs.Notify(
                                        $q.lang.selectHelper.warning,
                                        $q.lang.queryPlan.subWarning.isInt,
                                        'warning',
                                      );
                                    }
                                  } else {
                                    delete WarnSubObj.value
                                      .ComplexTriggerConditionView.CompareValue;
                                  }
                                  if (
                                    WarnSubObj.value.ExecuteFrequency
                                      .SysFrequencies.length == 0
                                  ) {
                                    Funcs.Notify(
                                      $q.lang.selectHelper.warning,
                                      $q.lang.queryPlan.subWarning
                                        .rateIsNotEmpt,
                                      'warning',
                                    );
                                    return;
                                  }
                                }
                                active.value++;
                              }}
                              style={
                                active.value == 1 ? 'width:100%' : 'width:50%'
                              }
                            >
                              {$q.lang.queryPlan.subWarning.nextStep}
                            </tm-button>
                          );
                        } else {
                          return (
                            <tm-button
                              class='submit'
                              type='primary'
                              color='primary'
                              style={'width:50%'}
                              onClick={() => {
                                if (
                                  WarnSubObj.value.NoticeSet.NoticeType == 1
                                ) {
                                  if (!WarnSubObj.value.NoticeSet.TokenInfo) {
                                    // this.Notify("warning", Terms.notify.TokenInfo);
                                    Funcs.Notify(
                                      $q.lang.selectHelper.warning,
                                      $q.lang.queryPlan.subWarning
                                        .tokenIsNotEmpt,
                                      'warning',
                                    );
                                    return;
                                  }
                                  if (!WarnSubObj.value.NoticeSet.SecretInfo) {
                                    Funcs.Notify(
                                      $q.lang.selectHelper.warning,
                                      $q.lang.queryPlan.subWarning
                                        .secrtIsNotEmpt,
                                      'warning',
                                    );
                                    return;
                                  }
                                  if (
                                    WarnSubObj.value.NoticeSet.IsNeedAtPerson &&
                                    !WarnSubObj.value.NoticeSet.PersonField
                                  ) {
                                    Funcs.Notify(
                                      $q.lang.selectHelper.warning,
                                      $q.lang.queryPlan.subWarning
                                        .notifyPersonIsNotEmpt,
                                      'warning',
                                    );
                                    return;
                                  }
                                }
                                WarnSubObj.value.NoticeSets = [
                                  WarnSubObj.value.NoticeSet,
                                ];
                                WarnSubObj.value.Description =
                                  WarnSubObj.value.Name;
                                if (WarnSubObj.value.TriggerType != 3) {
                                  delete WarnSubObj.value
                                    .ComplexTriggerConditionView.CompareValue;
                                }
                                WarnSubObj.value.ComplexTriggerCondition =
                                  JSON.stringify(
                                    WarnSubObj.value
                                      .ComplexTriggerConditionView,
                                  );
                                WarnSubObj.value.LinkUrl = document.URL;
                                let dParameters = [];
                                let dataSource = ref(
                                  dataQuery.value
                                    ? JSON.parse(dataQuery.value)
                                    : null,
                                );
                                if (dataSource.value) {
                                  WarnSubObj.value.JSContent = dataSource.value
                                    .DataBind
                                    ? dataSource.value.DataBind
                                    : dataSource.value.DisplayInfo; // DQ的数据源——春辉（查询方案的数据源）  Widget.fas_advquery
                                  dParameters = dataSource.value.Parameters;
                                }
                                let pLength = dParameters.length;
                                let JSContentParams = {};
                                for (let i = 0; i < pLength; i++) {
                                  let pCode = dParameters[i].Code;
                                  if (pCode == 'AdvancedFilter') {
                                    JSContentParams['AdvancedFilter'] =
                                      FilterExpression(
                                        modifyPlan.value,
                                        filterServer.value,
                                      );
                                  } else {
                                    JSContentParams[dParameters[i].Code] = null;
                                  }
                                }
                                WarnSubObj.value.JSContentParams =
                                  JSON.stringify(JSContentParams);
                                WarnSubObj.value.BusinessName = pageName.value;
                                //pageID.value ?? '';
                                WarnSubObj.value.BusinessType = pageCode.value;
                                // pageID.value ?? '';
                                CreateScheduleJobSubscription(
                                  WarnSubObj.value,
                                ).then(res => {
                                  if (res.data) {
                                    Funcs.Notify(
                                      $q.lang.selectHelper.warning,
                                      $q.lang.queryPlan.subWarning.subSuccess,
                                      'success',
                                    );

                                    emit('update:showSubWarning', false);
                                    emit('subWarning', res.data);
                                  } else {
                                    Funcs.Notify(
                                      $q.lang.selectHelper.warning,
                                      $q.lang.queryPlan.subWarning.subFail.format(
                                        res.message,
                                      ),
                                      'warning',
                                    );
                                  }
                                });
                              }}
                            >
                              {$q.lang.label.ok}
                            </tm-button>
                          );
                        }
                      })()}
                    </div>
                  </div>
                );
              } else {
                return (
                  <div>
                    <div style='height:calc(80vh - 96px);overflow:auto'>
                      {renderBasicInfo(true)}
                      {renderSubInfo(true)}
                      {renderNotifyInfo(true)}
                    </div>
                    <div class='subwarning_foot'>
                      {(() => {
                        if (modifyPlan.value.IsAuth) {
                          return (
                            <tm-button
                              class='submit'
                              size='small'
                              style={'border:1px solid #DCDCDC;width:50%'}
                              onClick={() => {
                                emit('update:showSubWarning', false);
                              }}
                            >
                              {$q.lang.label.close}
                            </tm-button>
                          );
                        } else {
                          return (
                            <tm-button
                              class='submit'
                              size='small'
                              type='primary'
                              color='primary'
                              style={'width:100%'}
                              onClick={() => {
                                emit('update:showSubWarning', false);
                              }}
                            >
                              {$q.lang.label.close}
                            </tm-button>
                          );
                        }
                      })()}
                      {(() => {
                        if (modifyPlan.value.IsAuth) {
                          return (
                            <tm-button
                              class='submit'
                              type='primary'
                              color='primary'
                              size='small'
                              style={'width:50%'}
                              onClick={() => {
                                CancleScheduleJobSubscription(
                                  modifyPlan.value.WarningID,
                                ).then(res => {
                                  if (res.state == 1) {
                                    Funcs.Notify(
                                      $q.lang.selectHelper.warning,
                                      $q.lang.queryPlan.subWarning
                                        .cancelSubSuceess,
                                      'success',
                                    );
                                    emit('update:showSubWarning', false);
                                    emit('subWarning', 'cancel');
                                  } else {
                                    Funcs.Notify(
                                      $q.lang.selectHelper.warning,
                                      $q.lang.queryPlan.subWarning.cancelSubFail.format(
                                        res.message,
                                      ),
                                      'warning',
                                    );
                                    emit('update:showSubWarning', false);
                                    emit('subWarning', 'cancel');
                                  }
                                });
                              }}
                            >
                              {$q.lang.queryPlan.subWarning.cancelSub}
                            </tm-button>
                          );
                        }
                      })()}
                    </div>
                  </div>
                );
              }
            })()}
          </div>
        </tm-popup>
      );
      // return <span>1111</span>;
    };
    return render;
  },
});
